package com.xuyiwei.xblog.business.system.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.xuyiwei.xblog.business.system.dao.ConfigMapper;
import com.xuyiwei.xblog.business.system.model.Config;
import com.xuyiwei.xblog.business.system.service.IConfigService;
import com.xuyiwei.xblog.core.base.constant.consts.DateConst;
import com.xuyiwei.xblog.core.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.Map;

/**
 * <p>
 * 系统配置 服务实现类
 * </p>
 *
 * @author xuyiwei
 * @since 2018-10-28
 */
@Service
public class ConfigServiceImpl extends ServiceImpl<ConfigMapper, Config> implements IConfigService {

    @Autowired
    private ConfigMapper configMapper;

    @Override
    public Config get() {
        return configMapper.get();
    }

    @Override
    public Map<String, Object> getSiteInfo() {
        Map<String, Object> map = configMapper.getSiteInfo();
        if (!CollectionUtils.isEmpty(map)) {
            Date recordeTime = (Date) map.get("recordeTime");
            if (!StringUtils.isEmpty(recordeTime)) {
                map.put("recordeTime", DateUtil.date2Str(recordeTime, "yyyy年MM月dd日HH点"));
            }
            Date buildSiteDate = DateUtil.str2Date("2016-10-27 00:00:00", DateConst.YYYY_MM_DD_HH_MM_SS_EN);
            // 获取建站天数
            map.put("buildSiteDate", DateUtil.getGapDay(buildSiteDate, new Date()));
        }
        return map;
    }
}
